package com.jhoncy.myproject.util;

import java.util.Random;
import java.util.UUID;

/**
 * @author zhuangqi
 * @@date 2017/3/14.
 */
public class UUIDUtil {
    /**
     * 获得一个UUID
     * @return String UUID
     */
    public static String getUUID(){
        String s = UUID.randomUUID().toString();
        //去掉“-”符号
        return s.substring(0,8)+s.substring(9,13)+s.substring(14,18)+s.substring(19,23)+s.substring(24);
    }


    /**
     * 获得特定UUID
     * USER_XR3Q_041211
     * @return String UUID
     */
    public static String getUUID(String fix){
        String s = UUID.randomUUID().toString();
        String num = System.currentTimeMillis()+"";
        return fix+"_"+s.substring(9,13)+"_"+num.substring(6,12);
    }


    /**
     * 获得短型特定UUID
     * XR3Q_041211
     * @return String UUID
     */
    public static String getSortUUID(){
        String s = UUID.randomUUID().toString();
        String num = System.currentTimeMillis()+"";
        return s.substring(9,13)+"_"+num.substring(6,12);
    }


    /**
     * 获得一个UUID
     * @return String UUID
     */
    public static Long getNumUUID(){
        return System.currentTimeMillis();
    }

    /**
     * 获取一个指定长度的数字字符器
     * @return
     */
    public static String getNumUUID(int num){
        String nums="0123456789";
        Random rand=new Random(System.currentTimeMillis());
        StringBuffer sb=new StringBuffer();
        for(int i=0;i<num;i++){
            sb.append(nums.charAt(rand.nextInt(nums.length())));
        }
        return sb.toString();
    }
}
